﻿using System;
using System.Web.UI.WebControls;
using System.Data.SqlClient;


namespace UserControls
{
    public partial class VerticalMenu : System.Web.UI.UserControl
    {
        AccessData ac;
        private HiddenField hrId;
        private Repeater rpChildrent;
        protected void Page_Load(object sender, EventArgs e)
        {
            ac = new AccessData();
            if (!Page.IsPostBack)
            {
                Load_ParentCategory();
            }
        }
        protected void Load_ParentCategory()
        {
            string sql = "select *from Categories where ParentID = 0";
            rpListParentCategory.DataSource = ac.GetTable(sql);
            rpListParentCategory.DataBind();
        }
        protected void rpListParentCategory_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            hrId = (HiddenField)e.Item.FindControl("hrID");
            rpChildrent = (Repeater)e.Item.FindControl("rpListChildCategory");
            if ((hrId != null) && (rpChildrent != null))
            {
                string sql = "select *from Categories where ParentID = " + hrId.Value.ToString();
                rpChildrent.DataSource = ac.GetTable(sql);
                rpChildrent.DataBind();

            }
        }
        // IF LEVEL 3 MENU
        //protected void rpListParentCategory_ItemDataBound2(object sender, RepeaterItemEventArgs e)
        //{

        //    HiddenField hrId = (HiddenField)e.Item.FindControl("hr2ID");
        //    Repeater rpChildrent = (Repeater)e.Item.FindControl("rpListChild2Category");
        //    if ((hrId != null) && (rpChildrent != null))
        //    {
        //        string sql = "select *from Categories where ParentID = " + hrId.Value.ToString();
        //        rpChildrent.DataSource = ac.GetTable(sql);
        //        rpChildrent.DataBind();
        //    }
        //}
    }
}
